<template>
    <div class="wage-calculator">
        <h1>牛马收益</h1>
        <div class="calculator-container">
            <div class="header">实时工资计算器</div>
            <div class="input-group">
                <label>月薪：（人民币）</label>
                <input v-model="monthlySalary" placeholder="请输入月薪" />
            </div>
            <div class="input-group">
                <label>每天工作小时数：</label>
                <input v-model="dailyWorkHours" placeholder="请输入每日工作小时数（例如：8小时：8）" />
            </div>
            <div class="input-group">
                <label>当月上班天数：</label>
                <input v-model="workDays" placeholder="请输入当月上班天数" />
            </div>
            <button @click="calculateRealTimeWage">开始上班</button>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                monthlySalary: '',
                dailyWorkHours: '',
                workDays: ''
            };
        },
        methods: {
            calculateRealTimeWage() {
                if (!this.monthlySalary || !this.dailyWorkHours || !this.workDays) {
                    window.alert('请确保月薪、每天工作小时数和当月上班天数都已输入。');
                    return;
                }
                // 验证输入是否为数字
                if (isNaN(this.monthlySalary) || isNaN(this.dailyWorkHours) || isNaN(this.workDays)) {
                    window.alert('请确保输入的月薪、每天工作小时数和当月上班天数都是数字。');
                    return;
                }
                // 验证 dailyWorkHours 在 0 - 24 之间
                if (parseFloat(this.dailyWorkHours) < 0 || parseFloat(this.dailyWorkHours) > 24) {
                    window.alert('每天工作小时数必须在 0 - 24 之间。');
                    return;
                }
                // 验证 workDays 在 0 - 32 之间
                if (parseFloat(this.workDays) < 0 || parseFloat(this.workDays) > 32) {
                    window.alert('当月上班天数必须在 0 - 32 之间。');
                    return;
                }
                this.$router.push({
                    path: '/salaryViewResult',
                    query: {
                        monthlySalary: this.monthlySalary,
                        dailyWorkHours: this.dailyWorkHours,
                        workDays: this.workDays
                    }
                });
            }
        }
    };
</script>

<style scoped>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    .wage-calculator {
        width: 100vw;
        height: 100vh;
        background-color: #888;
        padding: 20px;
        text-align: center;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    h1 {
        color: white;
        width: 548px;
        height: 157px;
        font-size: 100px;
        font-family: STXinwei;
    }

    .calculator-container {
        width: 80%;
        height: 80%;
        background-color: white;
        border-radius: 10px;
        padding: 20px;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .header {
        width: 100%;
        /* height: 40%; */
        background-color: #f0c040;
        color: white;
        padding: 10px;
        border-radius: 10px;
        font-weight: bold;
        margin-bottom: 20px;
    }

    .input-group {
        width: 100%;
        margin-bottom: 15px;
        text-align: left;
        font-size: 30px;
    }

    input {
        width: 100%;
        height: 80px;
    }

    label {
        display: block;
        margin-bottom: 5px;
        color: #f0c040;
    }

    input {
        width: 100%;
        padding: 8px;
        border: 1px solid #ccc;
        border-radius: 4px;
    }

    button {
        background-color: #f0c040;
        color: white;
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
    }
</style>